 

<div class="layui-fluid">
    <div class="layui-row layui-col-space12"> 
        <div class="layui-col-md12">
            <div class="layui-param-right1">
                <div class="layui-form-top">
                    <div class="layui-collapse" lay-filter="custom-collapse-filter">
                        <form action="" class="layui-form my-custom-form" lay-filter="my-form-filter">
                           
                            <div class="layui-colla-item"> 
                                <div class="layui-colla-content layui-show">
                                    <div class="layui-form-item">
                                        <div class="layui-row">
                                            <div class="layui-col-md6">
                                                <div class="layui-inline">
                                                    <label class="layui-form-label">版本：</label>
                                                    <div class="layui-input-inline" style="margin-right: 40px;">
                                                        <select name="version_id" lay-verify="required" id="custom-version-select" lay-filter="version-select-filter"></select>
                                                    </div>
                                                    <div class="layui-input-inline">
                                                        <select name="zbtype" lay-verify="required" id="custom-level-select" lay-filter="level-select-filter"></select>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="layui-col-md6">
                                                <div class="layui-inline-block">
                                                    <label class="layui-form-label">任务名称：</label>
                                                    <div class="layui-input-block">
                                                        <input type="text" name="taskname" required lay-verify="required" autocomplete="off" class="layui-input">
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-row">
                                            <div class="layui-col-md6">
                                                <div class="layui-inline">
                                                    <label class="layui-form-label">开始时间：</label>
                                                    <div class="layui-input-inline my-custom-input" style="margin-right: 15px;">
                                                        <input type="text" name="starttime" required lay-verify="required" class="layui-input" id="my-starttime-input">
                                                        <div class="calendar">
                                                            <div class="calendar-box" id="calendar-start"></div>
                                                        </div>
                                                    </div>

                                                    <label class="layui-form-label">结束时间：</label>
                                                    <div class="layui-input-inline my-custom-input">
                                                        <input type="text" name="endtime" required lay-verify="required" class="layui-input" id="my-endtime-input">
                                                        <div class="calendar">
                                                            <div class="calendar-box" id="calendar-end"></div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="layui-col-md6">
                                                <div class="layui-inline-block">
                                                    <label class="layui-form-label">年份：</label>
                                                    <div class="layui-input-block">
                                                        <input type="text" name="year" required lay-verify="required" class="layui-input" id="dateYear">
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item" style="margin:0;">
                                        <div class="layui-row">
                                            <div class="layui-col-md6">
                                                <button type="button" class="layui-btn layui-btn-sm bgBlue" id="my-upload-btn"><i class="layui-icon layui-icon-upload"></i>附件上传</button>
                                                <div class="layui-input-block" style="margin-left: 88px;">
                                                    <div class="check-value-box" id="temporary-upload-files"></div>
                                                </div>
                                            </div>
                                            <div class="layui-col-md6">
                                                <label class="layui-form-label">说明：</label>
                                                <div class="layui-input-block" style="margin-left:80px;">
                                                    <input type="text" name="memo" class="layui-input">
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="buttons-area">
                                <button type="button" lay-submit class="layui-btn lay-submit" lay-filter="formSubmit">确定</button>
                                <button type="button" class="cancelSubmit layui-btn" data-target="cancel" >取消</button>
                            </div>
                        </form>
                    </div>
                </div>
                <div class="layui-form-bottom">
                    <div class="layui-form" lay-filter="my-province-form">
                        <div class="layui-inline">
                            <div class="layui-input-inline"> 
                                <button type="button" class="layui-btn layui-hide layui-btn-settime bgBlue T-btn" data-target="setTime">
                                    <i class="layui-icon layui-icon-log"></i>
                                    设置填报时间
                                </button>
                            </div>
                            <div class="layui-input-inline">
                                <div class="layui-province-box">
                                    <select name="province" id="custom-province-select" lay-filter="province-select-filter"></select>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form" lay-filter="my-fomula-filter">
                        <table id="my-custom-table1" lay-filter="indicators-table1"></table>
                    </div>
                </div>
               
            </div>
        </div>
    </div>
</div>

<style>
    .layui-param-left, .layui-param-right1{
        height:100%;
        /* border:1px solid #90ABCD;
        border-radius:4px; */
        background-color: #FFFFFF;
        overflow: hidden;
    }
    .layui-header-title{
        padding-left: 30px;
        position: relative;
    }
    .layui-card-header{
        height: 39px;
        line-height: 39px;
        border-bottom: 1px solid #D0D3DB;
        background-color: #F6F7F8;
    }
    .layui-header-title .param-icon{
        width: 18px;
        height: 18px;
        background: url('/dist/style/res/formFill/tem-task.png') no-repeat center center;
        margin-top: -10px;
        left: 0px;
    }
    .custom-ztree{
        border: 1px solid #A3C4ED;
        height: 760px;
        border-radius: 5px;
        overflow: hidden;
    }
    .custom-ztree .layui-table-cell{
        padding: 0;
    }
    .layui-param-left .layui-card-body{
        padding: 13px 10px 0 10px;
    }
    .layui-input-block{
        margin-left: 80px;
    }
    .icon-progress{
        display: inline-block;
        width: 8px;
        height: 8px;
        border-radius: 50%;
    }
    .layui-layer-tips{
        position: relative;
        z-index: 2;
        box-shadow: 0px 0px 5px #cccccc;
    }
    .layui-layer-tips .layui-icon-close{
        position: absolute;
        color: #000000;
        right: 0;
        top: 0;
        cursor: pointer;
    }
    .layui-layer-tips i.layui-layer-TipsR{
        top: 50%;
        margin-top: -8px;
    }
    .layui-layer-tips .layui-layer-content{
        text-align: center;
        border-radius: 5px;
        padding-top: 18px;
    }
    .my-table-btn-del, .my-table-btn-edit, .my-table-btn-download{
        font-size: 20px;
		border-width: 1px;
		border-style: solid;
		border-radius: 4px;
        cursor: pointer;
	}
    .my-table-btn-del{
        color: #FF4E32 !important;
		border-color: #FF4E32;
    }
    .my-table-btn-edit{
        color: #FFA022 !important;
		border-color: #FFA022;
    }
    .my-table-btn-download{
        display: inline-block;
        width: 24px;
        height: 22px;
        background: url('/dist/style/res/param/createTask/down.png') no-repeat center center;
        border-color: #4ECB64;
        vertical-align: middle;
        margin-top: -7px;
    }
    .layui-btn-save{
        position: absolute;
        top: 5px;
        right: 15px;
        width: 71px;
        height: 30px;
        line-height: 30px;
        text-align: right;
        padding: 0 10px;
        color: #FFFFFF;;
        /* background: url('/start/TheForm/css/img/form-save.png') no-repeat 10px 7px #2669B1; */
        background: url('../../dist/style/res/formFill/saveForm.png') no-repeat 10px center #2669B1;
    }
    .my-custom-form .layui-input, .my-custom-form select{
        height: 35px;
        line-height: 35px;
        border:1px solid #C5C5C5;
        border-radius: 6px;
    }
    .my-custom-form .layui-form-label{
        padding: 7px 0px;
    }
    .my-custom-form .layui-form-item{
        margin-bottom: 22px;
    }
    .layui-form-top .layui-card-body{
        padding: 23px 15px;
    }
    .my-custom-input{
        position: relative;
    }
    .my-custom-input .calendar{
        width: 30px;
        height: 35px;
        text-align: center;
        line-height: 35px;
        position: absolute;
        right: 0px;
        top: 0px;
    }
    .calendar-box{
        position: absolute;
        top: 50%;
        left: 50%;
        width: 20px;
        height: 20px;
        transform: translate(-50%, -50%);
        background: url("/dist/style/res/param/createTask/calendar.png") no-repeat center center;
        background-size: cover;
        cursor: pointer;
    }
    .calendar-box:hover{
        background-image: url("/dist/style/res/param/createTask/calendar-h.png");
    }
    .layui-table tr td{
        vertical-align: middle;
    }
    #my-custom-table1{
        border: 1px solid #D2D2D2;
    }
    .layui-form-bottom{
        padding: 10px 12px 0;
    }
    .layui-form-bottom table{
        border: 1px solid #D2D2D2;
        background-color: #F2F7FD;
    }
    .factors{
        text-align: right;
    }
    .factors .factor-item{
        display: inline-block;
        vertical-align: middle;
        margin-right: 5px;
    }
    .factor-item-build, .factor-item-done{
        display: inline-block;
        width: 8px;
        height: 8px;
        border-radius: 50%;
        margin-right: 5px;
    }
    .factor-item-build-text, .factor-item-done-text{
        font-size: 14px;
        color: #666666;
    }
    .my-custom-form .unit-content {
        display: inline-block;
        padding: 2px 5px;
        padding-right: 15px;
        background-color: #ccc;
        position: relative;
        height: 20px;
        line-height: 20px;
    }
    .my-custom-form .unit-content:hover i{
        visibility: visible;
        color: red;
        font-weight: 600;
    }
    .my-custom-form .unit-content:hover a {
        text-decoration: underline;
    }
    .my-custom-form .unit-content i {
        position: absolute;
        right: 0px;
        top: -2px;
        font-size: 14px;
        cursor: pointer;
        visibility: hidden;
    }
    .my-custom-form .check-value-box {
        height: 29px;
        overflow-y: auto;
        padding: 2px 2px;
        border: 1px solid #C5C5C5;
        border-radius: 6px;
    }
    #my-upload-btn, .layui-upload-wrap{
        float: left;
        height: 35px;
    }
    .layui-badge {
		height: 23px;
		line-height: 23px;
		border-radius: 10px;
        padding: 0 21px;
	}
    @media screen and (min-width: 992px){
        .layui-col-md3 {
            width: 20%;
        }
        .layui-col-md9{
            width: 80%;
        }
    }
    .layui-colla-item{
        position: relative;
    }
    .layui-table-page{
        line-height: 41px;
    }
    .layui-colla-title{
        height: 39px;
        line-height: 39px;
        background-color: #F6F7F8;
    }
    .layui-table-page .layui-laypage a, .layui-table-page .layui-laypage span.layui-laypage-curr {
        padding: 0 5px;
    }
    .buttons-area { 
        height: 40px;
        text-align: center;
        position: absolute;
        bottom: -46px;
        z-index: 999;
        width: 100%;
    }
    .buttons-area button{
        background-color: #2669B1;
    }
</style>

<!-- 输入框模板 -->
<script type="text/html" id="datascore">
    {{# if(d.examine === 0){ }}
        <button type="button" class="layui-btn layui-btn-sm layui-btn-warn T-btn" data-target="examine" data-examine="{{d.examine_record}}"></button>
    {{# } }}
   <div class="layui-alg-select"></div>
    {{# if(!!d.write_value){ }}
        <input type="text" name="percent{{d.LAY_TABLE_INDEX}}" id="percent{{d.LAY_TABLE_INDEX}}" data-id="{{d.id}}" data-itemId="{{d.item_id}}" data-showVal="{{d.show_value}}" data-writeVal="{{d.write_value}}" class="layui-input my-input-style" value="{{d.write_value}}"/>
    {{# }else if(!!d.show_value){ }}
        <input type="text" name="percent{{d.LAY_TABLE_INDEX}}" id="percent{{d.LAY_TABLE_INDEX}}" data-id="{{d.id}}" data-itemId="{{d.item_id}}" data-showVal="{{d.show_value}}" data-writeVal="{{d.write_value}}" class="layui-input my-input-style" value="{{d.show_value}}"/>
    {{# }else if(!!d.datascore){ }}
        <input type="text" name="percent{{d.LAY_TABLE_INDEX}}" id="percent{{d.LAY_TABLE_INDEX}}" data-id="{{d.id}}" data-itemId="{{d.item_id}}" data-showVal="{{d.show_value}}" data-writeVal="{{d.write_value}}" class="layui-input my-input-style" value="{{d.datascore}}"/>
    {{# }else{ }}
        <input type="text" name="percent{{d.LAY_TABLE_INDEX}}" id="percent{{d.LAY_TABLE_INDEX}}" data-id="{{d.id}}" data-itemId="{{d.item_id}}" data-showVal="{{d.show_value}}" data-writeVal="{{d.write_value}}" class="layui-input my-input-style" value=""/>
    {{# } }}
    <span>请输入数值。</span>
</script>

<!-- 上传文件展示模板 -->
<script type="text/html" id="temporaryuploadFilesTpl">
    {{#
        layui.each(d, function(index,item) {
    }}
        <div class="unit-content">
			<a class="T-btn" data-target="downFile" href="javascript: void(0);" data-url="{{item.url}}">{{item.filename}}</a>
            <i class="layui-icon layui-icon-close T-btn" data-target="delFile" data-deptid="{{item.servername}}"></i>
        </div>
    {{#
        })
    }}
</script>

<!-- 任务列表状态栏 -->
<script type="text/html" id="temporarystatusTpl">
    {{#
		var getStatusColor = function() {
			var mapColors = {
                '00': 'layui-bk-green',
                '05': 'layui-bk-orange',
                '20': 'layui-bk-gray',
                '25': 'layui-bk-orange',
                '30': 'layui-bk-green',
                '40': 'layui-bk-orange',
                '90': 'layui-bk-gray',
                '99': 'layui-bk-gray'
			};
			return mapColors[d.state] || '';
		};
	}}
	<span class="custom-badge {{getStatusColor()}}">{{d.statename}}</span>	
</script>


<!-- 操作栏工具栏 -->
<script type="text/html" id="opelTol">
    {{# if(d.state == '00'){ }}
        <a class="layui-icon layui-icon-delete my-table-btn-del" lay-tips="删除" lay-event="del"></a>
        <a class="layui-icon my-table-btn-download" lay-tips="下发" lay-event="dealt"></a>
    {{# } }}
</script>

<script>
     
    layui.use(['element', 'admin', 'form', 'laydate', 'upload', 'table', 'tools', 'laytpl', 'view', 'tableMerge'], function(){
        var element = layui.element,
            admin = layui.admin,
            form = layui.form,
            laydate = layui.laydate,
            upload = layui.upload,
            table = layui.table,
            tools = layui.tools,
            laytpl = layui.laytpl,
            view = layui.view,
            tableMerge = layui.tableMerge;

        form.render(null, 'my-form-filter');
        form.render(null, 'my-province-form');
        element.init();

        var versionId = '',
            zbType = '',
            tempFileName = '',
            liEvent = '',
            filenames = [],
            model = 'insert',
            taskId = '',
            isTaskSel = false,
            layout = ['.layui-table th', '.layui-table td'];
 
        renderLadate(); //加载日期时间选择框
        versionId = getVersionSelect(); //加载下拉框内容
        zbType = getLevelSelect(); 
        getProSelect(); //加载省份下拉框
        initTable(versionId, zbType); //加载指标表格
  
//加载侧边栏
function getTaskTree(){
            table.render({
                elem: '#indexdata-table',
                url: 'myapi/DC/api/rest/web/custom/IndexDataTaskQuery',
                where: {
                    model: 'create',
                    access_token: layui.data('layuiAdmin').access_token
                },
                height: 760,
                even: true,
                text: {
                    none: '<div class="no-data-tips"><img src="/src/style/res/about/empty.png"><p style="color:#DBDBDB;">暂无数据</p></div>'
                },
                page: {
                    groups: 1, 
                    limit: 10,
                    next:'<i class="layui-icon">&#xe602;</i>',
                    prev:'<i class="layui-icon">&#xe603;</i>',
                    first: '<i class="layui-icon">&#xe65a;</i>',
                    last: '<i class="layui-icon">&#xe65b;</i>',
                    layout: ['refresh', 'first', 'prev', 'skip', 'allPage', 'next', 'last'],
                    extend:{
                        first: true, //是否显示首页
                        spr: false,//是否显示页码分页符号 默认显示
                        pagecount: true//页码是否显示总数  groups=1时才有效
                    }
                },
                request: {
                    limitName: 'count'
                },
                parseData: function(res){
                    var data = res.data;
                    return {
                        "code": data.retcode, //解析接口状态
                        "msg": data.retmsg, //解析提示文本
                        "count": data.data.totalNumber, //解析数据长度
                        "data": data.data.data //解析数据列表
                    };
                },
                cols: [[
                    {
                        field: 'taskname', 
                        title:'任务名', 
                        align: 'center',
                        templet: function(d){
                            return '<span lay-tips='+d.taskname+'>'+d.taskname+'</span>'
                        }
                    },
                    {field: 'state', title: '状态', align: 'center',templet: '#temporarystatusTpl', width: 80}, 
                    {field: 'operate', title:'操作', toolbar: '#opelTol', align: 'center', width: 80}
                ]],
                done: function(res, curr, count){
                    if(res.data && res.count > 0){
                        taskId = res.data[0].id;
                        setVisible(res.data[0].state, res.data[0].zbtype);
                    }
                    tools.setFont(layout);
                }
            })
        }
        //加载时间选择和文件上传
        function renderLadate(){
            var date = new Date();
            //开始时间
            laydate.render({
                elem: '#my-starttime-input',
                eventElem: '#calendar-start',
                format: 'yyyy-MM-dd',
                min: '0',
                trigger: 'click'
            })
            //结束时间
            laydate.render({
                elem: '#my-endtime-input',
                eventElem: '#calendar-end',
                format: 'yyyy-MM-dd',
                min: '0',
                trigger: 'click'
            })
            //年份选择
            laydate.render({
                elem: '#dateYear',
                type: 'year',
                value: date.getFullYear()
            })
            //文件上传
			upload.render({
				elem: '#my-upload-btn',
				accept: 'file',
				url: 'myapi/DC/api/rest/web/custom/uploadfile?access_token='+layui.data('layuiAdmin').access_token,
				choose: function(obj) {
                    //预读本地文件，如果是多文件，则会遍历。(不支持ie8/9)
					// obj.preview(function(index, file, result){
					// 	tempFileName = file.name;
					// })
				},
				done: function(res, index, upload){ //上传后的回调
					if(res.retcode == 0) {
                        filenames.push({filename: res.filename, servername: res.servername, url: res.url}); 
						var getTpl = temporaryuploadFilesTpl.innerHTML,
						    $tplC = $('#temporary-upload-files');
						laytpl(getTpl).render(filenames, function(html){
							$tplC.html(html);
						});
					}else {
						layer.msg('提示: '+ res.retmsg,{time: 1500});
					}
				},
				error: function(index, upload){
					layer.msg('上传失败，请重新选择文件上传', {time: 1500});
				}
			})
        }

        /*加载指标数据表格*/
        function initTable(version_id, zbtype, taskid, deptcode){
            var param = {
                version_id: version_id,
                zbtype: zbtype
            }
            if(taskid){ param.taskid = taskid }
            if(deptcode){ param.dept_code = deptcode }
            admin.req({
                url: 'myapi/DC/api/rest/web/custom/IndexTreeByVerAndType',
                type: 'post',
                data: param,
                done: function(res){
                    if(res.data.retcode == 0){
                        var data = res.data.data,
                            head = data.head,
                            leafs = data.alg_leafs;
                        for(var i = 0; i < head.length; i++){
                            if(i == 0){ head[i].merge = true; }
                            else{ head[i].merge = [head[i-1].field, head[i].field]; }
                            head[i].minWidth = 200;
                            head[i].align = 'center';
                            (function(i){ 
                                head[i].templet = function(d){
                                    var field = d[head[i].field];
                                    if(field != 'datascore'){
                                        return '<span lay-tips='+field+'>'+field+'</span>'
                                    }
                                };
                            })(i);
                        }
                        head.push({ field: 'datascore', templet: '#datascore', align: 'left', minWidth: 300 });
                        table.render({
                            elem: '#my-custom-table1',
                            height: 340,
                            text: {
                                none: '<div class="no-data-tips"><img src="/src/style/res/about/empty.png"><p style="color:#DBDBDB;">暂无数据</p></div>'
                            },
                            limit: 10000,
                            data: data.data,
                            cols: [head],
                            done: function(res, curr, count){
                                tableMerge.render(this);
                                initAlgSelect(leafs);
                                tools.setFont(layout);
                            }
                        })
                    }
                }
            })
        }

        //加载级别下拉框
        function getVersionSelect(){
            var ajaxData = admin.req({
                url: 'myapi/DC/api/rest/web/custom/GetIndexVersions',
                async: false,
                success: function(res){
                    if(res.retcode == '0'){
                        var data = res.data.data,
                            html = '';
                        if(data && data.length > 0){
                            layui.each(data, function(index, item){
                                if(index == 0){
                                    html += "<option value="+item.id+" data-year="+item.year+" selected>"+item.text+"</option>"
                                }else{
                                    html += "<option value="+item.id+" data-year="+item.year+">"+item.text+"</option>"
                                }
                            })
                            $('#custom-version-select').html(html);
                            form.render(null, 'my-form-filter');
                        }
                    }
                }
            })
            return ajaxData.responseJSON.data.data[0].id;
        }

        //加载级别下拉框
        function getLevelSelect(){
            var ajaxData = admin.req({
                url: 'myapi/DC/api/rest/web/custom/GetStateComboBox',
                async: false,
                success: function(res){
                    if(res.retcode == '0'){
                        var data = res.data.data,
                            html = '';
                        if(data && data.length > 0){
                            layui.each(data, function(index, item){
                                if(index == 0){
                                    html += "<option value="+item.id+"  selected>"+item.text+"</option>"
                                }else{
                                    html += "<option value="+item.id+" >"+item.text+"</option>"
                                }
                            })
                            $('#custom-level-select').html(html);
                            form.render(null, 'my-form-filter');
                        }
                    }
                }
            })
            return ajaxData.responseJSON.data.data[0].id;
        }

        //加载省份下拉框
        function getProSelect(){
            admin.req({
                url: 'myapi/DC/api/rest/web/custom/DCProvinceDeptComboBox',
                data: {},
                done: function(res){
                    if(res.data.retcode == 0){
                        var data = res.data.data,
                            html = '';
                        if(data && data.length > 0){
                            layui.each(data, function(index, item){ 
                                html += '<option value='+item.dept_code+'>'+item.dept_name+'</option>';
                            }) 
                        }
                        $('#custom-province-select').html(html);
                        form.render('select', 'my-province-form');
                    }
                }
            })
            $('.layui-province-box').addClass('layui-hide')
        }

        //重置表单
        function resetForm(){
            form.val('my-form-filter', {
                version_id: 'cs1',
                zbtype: '1',
                taskname: '',
                starttime: '',
                endtime: '',
                memo: ''
            });
            var getTpl = temporaryuploadFilesTpl.innerHTML,
                $tplC = $('#temporary-upload-files');
            laytpl(getTpl).render([], function(html){
                $tplC.html(html);
            });
        }

        /*设置填报时间按钮隐藏或显示
        @param state 任务状态
        */
        function setVisible(state, zbtype){
            if(state == '05'){ //已下发
                $('.layui-btn-settime').removeClass('layui-hide').addClass('layui-show');
                if(zbtype == '2'){ //省级任务
                    $('.layui-province-box').removeClass('layui-hide').addClass('layui-show');
                }else{
                    $('.layui-province-box').removeClass('layui-show').addClass('layui-hide');
                }
            }else {
                $('.layui-btn-settime').removeClass('layui-show').addClass('layui-hide');
                $('.layui-province-box').removeClass('layui-show').addClass('layui-hide');
            }
        }

        /*
        * 加载算法下拉框
        *@param leafs 下拉框的值
        */
        function initAlgSelect(leafs){
            var allScores = $('[lay-id="my-custom-table1"] tbody tr td[data-field="datascore"]');
            for(var i in leafs){
                var leafId = leafs[i][0].item_id;
                layui.each(allScores, function(index, item){
                    var iptId = $(this).find('input').data('itemid'),
                        showValue = $(this).find('input').data('showval') || '',
                        writeValue = $(this).find('input').data('writeval') || '';
                    if(iptId == leafId){
                        var container = $(this).find('.layui-alg-select'),
                            html = "<select class='myAlgSelect' lay-ignore><option value='' data-type='1'></option>";
                        layui.each(leafs[i], function(i,each){
                            var newVal;
                            if(each.formula.indexOf("<")>0){
                                newVal = each.formula.replace('<', '< ');
                            }else{
                                newVal = each.formula;
                            }
                            if(each.formula == showValue){ 
                                html += "<option value='"+each.formula+"' data-writeVal='"+(writeValue ? writeValue : '')+"' data-type='"+each.item_value_type+"' data-id="+each.id+" selected>"+newVal+"</option>";
                            }else{
                                html += "<option value='"+each.formula+"' data-writeVal='"+(writeValue ? writeValue : '')+"' data-type='"+each.item_value_type+"' data-id="+each.id+">"+newVal+"</option>";
                            }
                        })
                        html += "</select>";
                        container.html(html);
                    }
                })
            }
            initAlgInput(); 
        }

        //为算法或值时显示隐藏输入框
        function initAlgInput(){
            var allSelects = $('.myAlgSelect');
            layui.each(allSelects, function(index, item){
                var selType = $(this).find('option:selected').data('type'),
                    iptVal = $(this).find('option:selected').data('writeval');
                $(this).parent().siblings('input').removeAttr('name');
                if(selType == '1'){
                     $(this).parent().siblings().not('button').removeClass('show').addClass('hidden');
                }else{
                    $(this).parent().siblings('input').val(iptVal).removeClass('hidden').addClass('show');
                    $(this).parent().siblings('span').removeClass('show').addClass('hidden');
                }
            })
        }

        //监听form表单提交
        form.on('submit(formSubmit)', function(data){ 
            var field = data.field,
                param = {
                    model: model,
                    taskname: field.taskname,
                    version_id: field.version_id,
                    zbtype: field.zbtype,
                    year: field.year,
                    starttime: field.starttime,
                    endtime: field.endtime,
                    memo: field.memo,
                    fileMsg: JSON.stringify(filenames)
                };
            if(model == 'update'){
                param.taskid = taskId;
            }
            admin.req({
                url: 'myapi/DC/api/rest/web/custom/IndexDataTask',
                type: 'post',
                data: param,
                done: function(res){
                    if(res.data.retcode == 0){
                        model = 'insert';
                        resetForm();
                        getTaskTree();
                        layer.msg('保存成功', {time: 1500});
                        layer.closeAll('page'); 
                    }
                }
            })
        }) 
        //监听版本下拉框change事件
        form.on('select(version-select-filter)', function(data){
            versionId = data.value;
            zbType = $('#custom-level-select').val();
            if(isTaskSel){
                var isExit = $('.layui-province-box').hasClass('layui-show'),
                    province = $('#custom-province-select').val();
                isExit ?  initTable(versionId, zbType, taskId, province) : initTable(versionId, zbType, taskId);
            }else{
                initTable(versionId, zbType);
            }
        })

        //监听类型下拉框change事件
        form.on('select(level-select-filter)', function(data){
            versionId = $('#custom-version-select').val();
            zbType = data.value;
            if(isTaskSel){
                var isExit = $('.layui-province-box').hasClass('layui-show'),
                    province = $('#custom-province-select').val();
                if(isExit){
                    initTable(versionId, zbType, taskId, province);
                }else{
                    initTable(versionId, zbType, taskId);
                }
            }else{
                initTable(versionId, zbType);
            }
        })

        //监听省市下拉框change事件
        form.on('select(province-select-filter)', function(data){
            initTable(versionId, zbType, taskId, data.value);
        })

        
 

        

            /*比较两个对象是否相同
            * @param x {Object} 对象1
            * @param y {Object} 对象2
            * @return  {Boolean} true 为相等，false 为不等
            */
            function deepEqual(x, y) {
                // 指向同一内存时
                if (x === y) {
                    return true;
                }
                else if ((typeof x == "object" && x != null) && (typeof y == "object" && y != null)) {
                    if (Object.keys(x).length != Object.keys(y).length)
                        return false;
                
                    for (var prop in x) {
                        if (y.hasOwnProperty(prop))
                        {  
                        if (! deepEqual(x[prop], y[prop]))
                            return false;
                        }
                        else
                        return false;
                    }
                    return true;
                }
                else 
                return false;
            }

            //展示任务信息
            // function setTaskinfo(data){
            //     var fileMsg = data.fileMsg;
            //         model = 'update';
            //         taskId = data.id;
            //     form.val('my-form-filter', {
            //         version_id: data.version_id,
            //         zbtype: data.zbtype,
            //         taskname: data.taskname,
            //         starttime: data.starttime.substring(0, 10),
            //         endtime: data.endtime.substring(0, 10),
            //         memo: data.memo,
            //         year: data.year
            //     });
            //     if(fileMsg){
            //         var getTpl = temporaryuploadFilesTpl.innerHTML;
            //         var $tplC = $('#temporary-upload-files');
            //         laytpl(getTpl).render(fileMsg, function(html){
            //             $tplC.html(html);                        
            //         });
            //     }
            //     if(data.state == '00'){ 
            //         $('.layui-btn-save').removeClass('layui-hide').addClass('layui-show');
            //     }else{
            //         $('.layui-btn-save').removeClass('layui-show').addClass('layui-hide');
            //     }
            // }
        })
</script>